<?php
 /*
  *微商城首页模型类
  *@author  <!--blakefan 1621743934@qq.com -->
  */
namespace Home\Model; 
use Think\Model;
class IndexModel
{
	public function index()
	{
		$result='';
		$result['typetree']=$this->topType();
		$result['hotitem']=$this->hotItem();
		$result['banner']=$this->getBanner();
		return $result;

	}

	/*
	 *获取顶级分类
	 * return array
	 */
	private function topType()
	{
		$result='';
		$type=M('type');
		$result=$type->cache(true)->where('pid=%d',0)
					 ->order('sort desc')
		             ->limit(6)->getField('typeid,typename,wximg,sort');
		if(!empty($result))
		{
			return $result;
		}
		return '';
	}
	/*
	 *获取下单最多产品
	 *@return array
	 */
	private function hotItem()
	{
		$result='';
		$result=M('item')->cache(true)->where('inventory>0 AND platid !=0 ')
						 ->order('itemid desc')->limit(20)
						 ->getField('itemid',true);
		if(!empty($result))
		{
			
			
			$item=M('item');
			$map['itemid']=array('in',$result);
			$map['inventory']=array('gt',0);
			$res=$item->cache('true')->where($map)
			          ->getField('itemid,itemname,bn,price,itemimg');
			return $res;
		}
		return '';
		
	}
	/*
	 *获取首页Banner图广告
	 */
	private function getBanner()
	{
			$result='';
			$advertisement=M('advertisement');
			$result=$advertisement->getField('id,advimg');
			if(!empty($result))
			{
				return $result;
			}else{
				return '';
			}
	}

}